﻿IF EXISTS (SELECT * FROM information_schema.ROUTINES WHERE ROUTINE_TYPE = 'PROCEDURE' AND ROUTINE_NAME = 'VendedorGetList')
	BEGIN
		DROP  Procedure  VendedorGetList
	END
GO

CREATE PROCEDURE [dbo].[VendedorGetList] 	
	(	
		@empresaId AS INT,		
		@id AS VARCHAR(12) = NULL,
		@filtro AS VARCHAR(50) = NULL		
	)	
AS
BEGIN	
	SET NOCOUNT ON
	
	SELECT	Vendedor_Id AS Id, 
			Vendedor_Nombre + ' ' + Vendedor_Apellido1 + ' ' + Vendedor_Apellido2 AS Nombre
	FROM Vendedor
	WHERE Emp_Id = @empresaId	  
	  AND ((Vendedor_Nombre like '%' + ISNULL(@filtro,'') + '%') OR
			(Vendedor_Apellido1 like '%' + ISNULL(@filtro,'') + '%') OR
			(Vendedor_Apellido2 like '%' + ISNULL(@filtro,'') + '%'))
	  AND Vendedor_Id = ISNULL(@id, Vendedor_Id)

	SET NOCOUNT OFF
END
GO